﻿@inherits NFinal.View.RazorView<NFinal.Url.UrlRouteJsModel>
@using System.Collections.Generic
function StringFormat() {
    if (arguments.length == 0)
        return null;
    var str = arguments[0];
    for (var i = 1; i < arguments.length; i++) {
        var re = new RegExp('\\{' + (i - 1) + '\\}', 'gm');
        str = str.replace(re, arguments[i]);
    }
    return str;
}
var Url={
@{bool isFirstAction = true; bool isFirstController = true; }
@foreach (KeyValuePair<RuntimeTypeHandle, Dictionary<string, NFinal.Url.FormatData>> formatController in Model.formatControllerDictionary)
{
    Type controllerType = Type.GetTypeFromHandle(formatController.Key);
    string controllerName = controllerType.Namespace.Replace('.', '_') + "_" + controllerType.Name;

    if (isFirstController)
    {
        isFirstController = false;
    }
    else
    {
        @:,
    }
    isFirstAction = true;
    @:"@controllerName":{
    foreach (KeyValuePair<string, NFinal.Url.FormatData> formatMethod in formatController.Value)
    {
        @if (isFirstAction)
        {
            isFirstAction = false;
        }
        else
        {
            @:,
        }

        if (formatMethod.Value.actionUrlNames != null && formatMethod.Value.actionUrlNames.Length > 0)
        {
            @:"@formatMethod.Key":function(@string.Join(",", formatMethod.Value.actionUrlNames))
            @:{
                @:return StringFormat("@formatMethod.Value.formatUrl",@string.Join(",", formatMethod.Value.actionUrlNames));
            @:}
        }
        else
        {
            @:"@formatMethod.Key":function()
            @:{
                @:return "@formatMethod.Value.formatUrl";
            @:}
        }
    }
    @:}
}
};